import {request} from "@umijs/max";
import {covertTableData} from "@/utils/tableUtil";
import {COMMON, PERM} from "@/services/admin/typings";

export const fetchPermPage = async (params: COMMON.PageParam) => {
  const resp = await request<COMMON.PageResponse<PERM.PermVO>>('/api/perm/page', {
    method: 'GET',
    params
  })
  return covertTableData(resp)
}


export const addPerm = async (dto: PERM.UpdateDTO) => {
  return request<PERM.PermVO>('/api/perm/add', {
    method: 'POST',
    data: dto
  })
}


export const updatePerm = async (dto: PERM.UpdateDTO) => {
  return request<PERM.PermVO>('/api/perm/update', {
    method: 'POST',
    data: dto
  })
}

export const deletePerm = async (id: number) => {
  return request<PERM.PermVO>(`/api/perm/delete?id=${id}`, {
    method: 'POST',
  })
}


export const getPermTree = async () => {
  return request(`/api/menu/tree`)
}
